<%@ page contentType="text/html;charset=UTF-8" language="java" import="java.util.List" import="com.itheima.domain.Book" pageEncoding="UTF-8"%>
<%@ page import="com.itheima.domain.User" isELIgnored="false"%>
<html>
<head>
    <title>图书列表</title>
    <%--    需要下载link--%>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
</head>
<body>
<div class="container mt-4">
    <h2 class="mb-4">📚 所有图书</h2>
    <table class="table table-bordered table-hover">
        <thead class="table-dark">
        <tr>
            <th>ID</th>
            <th>书名</th>
            <th>作者</th>
            <th>价格</th>
            <th>图片</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>

            <%
            @SuppressWarnings("unchecked")
            List<Book> books = (List<Book>) request.getAttribute("bookList");
            request.getSession().getAttribute("user");
            for (Book book : books) {
            %>
                <tr>
                    <td><%= book.getId() %></td>
                    <td><%= book.getBookName() %></td>
                    <td><%= book.getAuthor() %></td>
                    <td><%= book.getPrice() %></td>
                    <td>
                        <img src="book/image/<%= book.getId() %>" width="100" height="150" alt=""/>
                    </td>
                    <td>
                        <a href="change/book?id=<%= book.getId() %>" class="btn btn-primary">
                            修改
                        </a>
                        <form action="borrow" method="post" style="display:inline;">
                            <input type="hidden" name="bookId" value="<%= book.getId() %>">
                            <input type="hidden" name="userId" value="<%= ((User)session.getAttribute("user")).getId() %>">
                            <button type="submit" class="btn btn-danger">借阅</button>
                        </form>

                    </td>
                    <td>
                        <div class="alert alert-info">${msg}</div>
                    </td>
                </tr>
            <%
            }
            %>
        </tbody>
        <a href="index.jsp"><i>返回主页</i></a>
    </table>
</div>
</body>
</html>
